<?php

class Zend_View_Helper_LoggedInAs extends Zend_View_Helper_Abstract {

    public function loggedInAs() {
        $auth = Zend_Auth::getInstance();
        if ($auth->hasIdentity()) {
            //$username = $auth->getIdentity()->username;
            $user = new Zend_Session_Namespace('login');
            $username = $user->userObj[0]['fname'];
           $logoutUrl = $this->view->url(array('controller' => 'auth',
                        'action' => 'logout'), null, true);
           $editUrl = $this->view->url(array('controller' => 'user',
                        'action' => 'profile'), null, true);
            return 'Welcome ' . $username . ' <a href="' . $editUrl . '"> Profile </a>
                    <a href="' . $logoutUrl . '"> Logout </a>';
        }

        $request = Zend_Controller_Front::getInstance()->getRequest();
        $controller = $request->getControllerName();
        $action = $request->getActionName();
        if ($controller == 'auth' && $action == 'index') {
            return '';
        }
        $loginUrl = $this->view->url(array('controller' => 'auth', 'action' => 'index'));
        return '<a href="' . $loginUrl . '"> Login </a>'."&nbsp;&nbsp;&nbsp;".'<a href='.$this->view->baseUrl().'/auth/signup> Register </a>';
    }

}